<template>
	<u-picker :show="show" :columns="columns" :closeOnClickOverlay="true" @cancel="show=false" @close="show = false"
		@confirm="confirm"></u-picker>
</template>

<script>
	import {
		listSpaceDiffTypeOptions
	} from '@/apis/goods/goods.js'

	export default {
		name: "select-space-diff-type",
		props: {
			value: {
				type: Number,
				default: 0
			},
			label: {
				type: String,
				default: "+"
			}
		},
		data() {
			return {
				show: false,
				options: [],
				columns: []
			}
		},
		created() {
			this.initData()
		},
		methods: {
			open() {
				this.show = true
			},
			confirm({
				value
			}) {
				const val = value[0]
				const options = this.options || []
				const targetOpt = options.find(item => {
					return item.label === val
				})
				this.show = false
				this.$emit("on-confirm", targetOpt)
				this.$emit("input", targetOpt.value)
				this.$emit("update:label", targetOpt.label)
			},
			initData() {
				listSpaceDiffTypeOptions().then(res => {
					if (!res.data.flag) return
					const data = res.data.data || []
					this.options = data || []
					this.columns = [data.map(item => {
						return item.label
					})]
				})
			}
		}
	}
</script>

<style>
</style>